/* SVN FILE: $Id: settings_controller.js 37 2007-08-26 22:57:19Z killergeorge $ */
/**
 * Short description for file.
 * 
 * jQuery is required
 * jamal is required
 * JamalBuilder:  Javascript MVC Assembler
 * Copyright (c)  2007, Georg Leciejewski <http://blog.mediaprojekte.de/>
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright        Copyright (c) 2006, Georg Leciejewski
 * @link            
 * @package          JamalBuilder
 * @subpackage       jamal.controllers.builds
 * @since            JamalBuilder v 0.1
 * @version          $Revision: 37 $
 * @modifiedby       $LastChangedBy: killergeorge $
 * @lastmodified     $Date: 2007-08-26 22:57:19 +0000 (Sun, 26 Aug 2007) $
 * @license          http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * SettingsController
 * 
 * controls the settings of the application by reading writing them to a XML file
 *
 */
$j.c({Settings: {

    /**
     * Build index
     * where you select a folder and build jamal
     */
    index: function () {
    	jamal.log('Start SettingsController index');

		var project_dir = null;
		var use_sound	= null;

		this.appendMainNav('Settings');
		
		$("#settingsForm").submit(function(e) {
				e.preventDefault();
				var data = $('#settingsForm').formToArray();
				jamal.airSettings.save(data);
				jamal.message.show('Saved your good old settings', 'success');
		});		

		var data  = jamal.airSettings.read();
		var name  = '';
		var value = '';
		//jamal.log(data);
		if(data)
		{	
			for (var i=0; i < data.length; i++ )
			{
				name = data[i].name;
				value =  data[i].value;
				if(name == 'use_sound')
				{//is a checkbox .. must abstract better later
					$('input[@name='+name+']').val(value).attr('checked', 'checked');					
				}
				else
				{
					$('input[@name='+name+']').val(value); 
				}	
			}			
		}
				
    }
		
	
}
});